package com.euond.permission.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.euond.common.core.dto.ResultDto;
import com.euond.common.web.controller.BaseCRUDController;
import com.euond.common.web.feign.integration.DictFeignService;
import com.euond.permission.entities.DataPrivilege;
import com.euond.permission.service.DataPrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.Action;
import java.util.Map;

/**
 * Created by user on 2018/1/6.
 */
@RestController
@RequestMapping("permission/front/dataprivileges")
public class DataPrivilegeController extends BaseCRUDController<DataPrivilegeService, DataPrivilege> {

    @Autowired
    DictFeignService dictFeignService;

    /**
     * 按条件查询实体列表以分页返回(覆盖基类)
     */
    @GetMapping(value = "page")
    public ResultDto listPage(@RequestParam(required = false) Map<String, Object> searchParams) {
        ResultDto resultDto = null;
        Page<DataPrivilege> dataPrivilegePage = baseService.selectListPageByMap(searchParams);
        if (dataPrivilegePage.getTotal() > 0) {
            //获取数据字典值
            Map<String, Object> map = dictFeignService.findDictByDictCode("data_type");
            if(map.size()>0){
                for(int i=0;i<dataPrivilegePage.getRecords().size();i++){
                    //公司
                    for (Map.Entry<String,Object> entry : map.entrySet()) {
                        String key = entry.getKey();
                        Object value = entry.getValue();
                        //假如id一致
                        if(dataPrivilegePage.getRecords().get(i).getDataType().toString().equals(key)){
                            dataPrivilegePage.getRecords().get(i).setDataTypeName(value.toString());
                        }
                    }
                }
            }
            resultDto=new ResultDto("0","seccess",dataPrivilegePage.getRecords(),dataPrivilegePage.getTotal());
        }else{
            resultDto=new ResultDto("9009","没有查到任何数据！");
        }
        return resultDto;
    }
}
